package cn.tedu.recruitmentwebsite.admin.service.impl;

import cn.tedu.recruitmentwebsite.admin.mapper.AdminMapper;
import cn.tedu.recruitmentwebsite.admin.pojo.dto.UserQuery;
import cn.tedu.recruitmentwebsite.admin.pojo.dto.UserSaveParam;
import cn.tedu.recruitmentwebsite.admin.pojo.entity.User;
import cn.tedu.recruitmentwebsite.admin.pojo.vo.UserVO;
import cn.tedu.recruitmentwebsite.admin.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public List<UserVO> query(UserQuery userQuery) {
        log.debug("查询用户的业务层 userQuery {}",userQuery);
        List<UserVO> userVO = adminMapper.query(userQuery);
        return userVO;
    }

    @Override
    public void save(UserSaveParam userSaveParam) {
        log.debug("保存用户的业务层 userSaveParam {}",userSaveParam);
        User user=new User();
        BeanUtils.copyProperties(userSaveParam,user);
        if(user.getId()==null){
            log.debug("保存用户，参数：{}", user);
            user.setCreateTime(new Date());
            user.setUserStatus("1");
            adminMapper.insert(user);
        } else {
            log.debug("修改用户，参数：{}", user);
            user.setUpdateTime(new Date());
            adminMapper.update(user);
        }
    }

    @Override
    public void update(Long id, String userStatus) {
        log.debug("修改用户业务层，参数：{}",id,userStatus);
        User user=new User();
        user.setId(id);
        user.setUserStatus(userStatus);
        adminMapper.update(user);
    }

    @Override
    public void delete(Long id) {
        log.debug("删除用户业务层，参数：{}",id);
        adminMapper.delete(id);
    }
}
